home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / APNDCUR.ASM < prev    next >
Assembly Source File  |  1992-03-13  |  4KB  |  178 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.         extrn    sl_malloc:far
  6.  
  7.  
  8. wp        equ    <word ptr>        ;I'm a lazy typist
  9.  
  10.  
  11. ; Special case to handle MASM 6.0 vs. all other assemblers:
  12. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  13.  
  14.         ifndef    @version
  15. @version    equ    500
  16.         endif
  17.  
  18.  
  19.  
  20. StdGrp        group    stdlib,stddata
  21. stddata        segment    para public 'sldata'
  22. stddata        ends
  23.  
  24. stdlib        segment    para public 'slcode'
  25.         assume    cs:stdgrp
  26.  
  27. ; sl_AppendCur -    DX:SI points at a list node.
  28. ;            ES:DI points at a list.
  29. ;            Insert the new node after "CurrentNode" in the
  30. ;            list.
  31. ;
  32. ; Randall Hyde  3/13/92
  33. ;
  34.  
  35.         public    sl_AppendCur
  36. sl_AppendCur    proc    far
  37.         push    ax
  38.         push    bx
  39.         push    ds
  40.         push    es
  41.         push    di
  42.  
  43.         if    @version ge 600
  44.  
  45. ; MASM 6.0 version goes here
  46.  
  47.         mov    ds, dx
  48.         cmp    wp es:[di].List.Head+2, 0    ;Empty list?
  49.         jne    HasAList
  50.  
  51. ; At this point, the HEAD pointer is zero.  This only occurs if the
  52. ; list is empty.  So point the Head, CurrentNode, and Tail pointers to
  53. ; the new node.
  54. ;
  55. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  56. ; package assumes that if the segment is zero, the whole thing is zero.
  57. ; So don't put any nodes into segment zero!
  58.  
  59.         mov    wp es:[di].List.Head, si
  60.         mov    wp es:[di].List.Head+2, dx
  61.         mov    wp es:[di].List.Tail, si
  62.         mov    wp es:[di].List.Tail+2, dx
  63.         mov    wp es:[di].List.CurrentNode, si
  64.         mov    wp es:[di].List.CurrentNode+2, dx
  65.  
  66.         mov    wp ds:[si].Node.Next, 0            ;Set all the links
  67.         mov    wp ds:[si].Node.Next+2, 0    ; in the first node
  68.         mov    wp ds:[si].Node.Prev, 0        ; to NIL.
  69.         mov    wp ds:[si].Node.Prev+2, 0
  70.         pop    di
  71.         pop    es
  72.         jmp    AppendDone
  73.  
  74. ; If the HEAD pointer is non-NIL, insert the new node after CurrentNode in
  75. ; the list down here.
  76.  
  77. HasAList:       les    di, es:[di].List.CurrentNode    ;Get ptr to current.
  78.  
  79.         mov    ax, wp es:[di].Node.Next    ;Get Next ptr.
  80.         mov    bx, wp es:[di].Node.Next+2
  81.  
  82.  
  83.         mov    wp es:[di].Node.Next, si    ;Insert the new node
  84.         mov    wp es:[di].Node.Next+2, dx    ; after the current
  85.  
  86.         mov    wp ds:[si].Node.Prev, di    ;Link in ptr
  87.         mov    wp ds:[si].Node.Prev+2, es    ; to "current" node.
  88.  
  89.         mov    wp ds:[si].Node.Next, ax    ;Store away ptr to
  90.         mov    wp ds:[si].Node.Next+2, bx    ; previous node.
  91.  
  92.         mov    di, ax                ;Get ptr to NEXT
  93.         mov    es, bx                ; node.
  94.         mov    wp es:[di].Node.Prev, si    ;Store away link to
  95.         mov    wp es:[di].Node.Prev+2, dx    ; new node.
  96.  
  97.         pop    di                ;Retrieve pointer to
  98.         pop    es                ; list variable.
  99.         mov    wp es:[di].List.CurrentNode, si    ;Store ptr to new
  100.         mov    wp es:[di].List.CurrentNode+2, ds ; current node.
  101.  
  102.  
  103.  
  104.  
  105.         else
  106.  
  107. ; This code is for the other assemblers.
  108.  
  109.         mov    ds, dx
  110.         cmp    wp es:[di].Head+2, 0        ;Empty list?
  111.         jne    HasAList
  112.  
  113. ; At this point, the HEAD pointer is zero.  This only occurs if the
  114. ; list is empty.  So point the Head, CurrentNode, and Tail pointers to
  115. ; the new node.
  116. ;
  117. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  118. ; package assumes that if the segment is zero, the whole thing is zero.
  119. ; So don't put any nodes into segment zero!
  120.  
  121.         mov    wp es:[di].Head, si
  122.         mov    wp es:[di].Head+2, dx
  123.         mov    wp es:[di].Tail, si
  124.         mov    wp es:[di].Tail+2, dx
  125.         mov    wp es:[di].CurrentNode, si
  126.         mov    wp es:[di].CurrentNode+2, dx
  127.  
  128.         mov    wp ds:[si].Next, 0            ;Set all the links
  129.         mov    wp ds:[si].Next+2, 0        ; in the first node
  130.         mov    wp ds:[si].Prev, 0        ; to NIL.
  131.         mov    wp ds:[si].Prev+2, 0
  132.         pop    di
  133.         pop    es
  134.         jmp    AppendDone
  135.  
  136. ; If the HEAD pointer is non-NIL, insert the new node after CurrentNode in
  137. ; the list down here.
  138.  
  139. HasAList:       les    di, es:[di].CurrentNode        ;Get ptr to current.
  140.  
  141.         mov    ax, wp es:[di].Next        ;Get Next ptr.
  142.         mov    bx, wp es:[di].Next+2
  143.  
  144.  
  145.         mov    wp es:[di].Next, si        ;Insert the new node
  146.         mov    wp es:[di].Next+2, dx        ; after the current
  147.  
  148.         mov    wp ds:[si].Prev, di        ;Link in ptr
  149.         mov    wp ds:[si].Prev+2, es        ; to "current" node.
  150.  
  151.         mov    wp ds:[si].Next, ax        ;Store away ptr to
  152.         mov    wp ds:[si].Next+2, bx        ; previous node.
  153.  
  154.         mov    di, ax                ;Get ptr to NEXT
  155.         mov    es, bx                ; node.
  156.         mov    wp es:[di].Prev, si        ;Store away link to
  157.         mov    wp es:[di].Prev+2, dx        ; new node.
  158.  
  159.         pop    di                ;Retrieve pointer to
  160.         pop    es                ; list variable.
  161.         mov    wp es:[di].CurrentNode, si    ;Store ptr to new
  162.         mov    wp es:[di].CurrentNode+2, ds     ; current node.
  163.  
  164.  
  165.  
  166.  
  167.         endif
  168.  
  169. AppendDone:    pop    ds
  170.         pop    bx
  171.         pop    ax
  172.         ret
  173.  
  174. sl_AppendCur    endp
  175.  
  176. stdlib        ends
  177.         end
  178.